﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace 桌面视频录制
{
    [Serializable]
    public class DrawAirBrush : DrawEllipse
    {
        private List<Point> pointList = new List<Point>();
        public DrawAirBrush(Point leftUpPoint)
        {
            this.leftUpPoint = leftUpPoint;
            for (int i = 0; i < 100; i++)
            {
                int dx = StaticFunction.random.Next(-10, 10);
                int dy = StaticFunction.random.Next(-10, 10);
                if (Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2)) > 10)
                    continue;
                pointList.Add(new Point(leftUpPoint.X + dx, leftUpPoint.Y + dy));
            }
        }
        public override void Draw(Graphics g)
        {
            Brush brush = new SolidBrush(this.PenColor);
            foreach (Point point in pointList)
            {
                g.FillEllipse(brush, point.X, point.Y, 2, 2);  
            }
            brush.Dispose();
            brush = null;
        }
        public override void MouseMove(System.Windows.Forms.MouseEventArgs e)
        {

        }
        public override bool JudgeIsSelected(System.Windows.Forms.MouseEventArgs e)
        {
            Rectangle rect = new Rectangle(leftUpPoint.X - 10, leftUpPoint.Y - 10, 20, 20);
            Rectangle rect1 = new Rectangle(e.X, e.Y, 1, 1);
            if (rect.IntersectsWith(rect1))
                return true;
            return false;
        }
        public override void DrawControlPoint(Graphics g)
        {
            //g.DrawRectangle(Pens.Red, leftUpPoint.X - 10, leftUpPoint.Y - 10, 20, 20);
        }
        public override void MoveLocation(MouseEventArgs e)
        {
            int dx = e.X - this.MouseDownPoint.X;
            int dy = e.Y - this.MouseDownPoint.Y;
            this.MouseDownPoint = new Point(e.X, e.Y);
            for (int i = 0; i < pointList.Count; i++)
            {
                pointList[i] = new Point(pointList[i].X + dx, pointList[i].Y + dy);
            }
        }
        public override bool JudgeIsInControlRegion(MouseEventArgs e)
        {
            return false;
        }
        public override void ChangeSize(MouseEventArgs e)
        {
            
        }
        public override string ToString()
        {
            string printMsg = "[喷枪(" + this.leftUpPoint.X + "," + this.leftUpPoint.Y + ")]->[ID:" + this.Id + "]";
            return printMsg;
        }
        public override string GetDrawObjectMsg()
        {
            string drawObjectMsg = "喷枪->起始位置(" + this.leftUpPoint.X + "," + this.leftUpPoint.Y + ")";
            return drawObjectMsg;
        }
        public override bool IsAllInRectangle(Region region)
        {
            foreach (Point point in pointList)
            {
                if (region.IsVisible(point) == false)
                    return false;
            }
            return true;
        }
    }
}
